<!DOCTYPE html>
<html>
<head>
<title>Same-origin CSS</title>

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<link rel="stylesheet"
      href="resources/redir.php?url=/security/resources/xorigincss1.html"></link>
<link rel="stylesheet"
      type="text/css"
      href="resources/redir.php?url=/security/resources/xorigincss2.html"></link>
<link rel="stylesheet"
      href="resources/redir.php?url=/security/resources/xorigincss1.css"></link>
<link rel="stylesheet"
      href="resources/xorigincss3.html"></link>
<style>
/* Deliberately reuse the same file / class / id on this first one */
@import "resources/redir.php?url=/security/resources/xorigincss2.html";
@import "resources/redir.php?url=/security/resources/xorigincss4.html";
@import "resources/redir.php?url=/security/resources/xorigincss7.html";
@import "resources/redir.php?url=/security/resources/xorigincss2.css";
@import "resources/xorigincss5.html";

/* Check that data: is still allowed for non-CORS cross-origin image fetches. */
#data-background-url {
    content: "PASS (image loaded)";
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='0px' height='0px'></svg>");
}
</style>
<script>
    function getBackgroundColorForId(id) {
        return window.getComputedStyle(document.getElementById(id), null).getPropertyValue('background-color')
    }
    var onloadTest = async_test("Testing same-origin and MIME behavior for CSS.");
    window.onload = function () {
        test(function () {
            assert_equals(getBackgroundColorForId('id1'), 'rgba(0, 0, 0, 0)');
        }, 'xorigincss1.html should not be loaded via <link>.');
        test(function () {
            assert_equals(getBackgroundColorForId('id2'), 'rgba(0, 0, 0, 0)');
        }, 'xorigincss2.html should not be loaded either via <link> or @import.');
        test(function () {
            assert_equals(getBackgroundColorForId('id3'), 'rgb(255, 255, 0)');
        }, 'xorigincss1.css should be loaded via <link>');
        test(function () {
            assert_equals(getBackgroundColorForId('id4'), 'rgba(0, 0, 0, 0)');
        }, 'xorigincss3.html should not be loaded, even though it is same-origin');
        test(function () {
            assert_equals(getBackgroundColorForId('id5'), 'rgba(0, 0, 0, 0)');
        }, 'xorigincss4.html should not be loaded via @import.');
        test(function () {
            assert_equals(getBackgroundColorForId('id6'), 'rgb(255, 255, 0)');
        }, 'xorigincss2.css should be loaded.');
        test(function () {
            assert_equals(getBackgroundColorForId('id7'), 'rgba(0, 0, 0, 0)');
        }, 'xorigincss5.html should not be loaded.');
        test(function () {
            assert_equals(getBackgroundColorForId('id8'), 'rgba(0, 0, 0, 0)');
        }, 'xorigincss7.html should not be loaded.');
        onloadTest.done();
    };
</script>
</head>
<body>
    <div id="id1" class="id1"></div>
    <div id="id2" class="id2"></div>
    <div id="id3" class="id3"></div>
    <div id="id4" class="id4"></div>
    <div id="id5" class="id5"></div>
    <div id="id6" class="id6"></div>
    <div id="id7" class="id7"></div>
    <div id="id8" class="id8"></div>
    <div id="data-background-url">PASS background image loaded</div>
</body>
</html>
